package com.dingxin.ship_together_api.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.dingxin.ship_together_api.entity.ShipInfo;
import com.dingxin.ship_together_api.entity.constant.PermissionConstant;
import com.dingxin.ship_together_api.entity.vo.PageQueryVo;
import com.dingxin.ship_together_api.service.ShipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SaCheckLogin
@RequestMapping("ship")
public class ShipController {
    @Autowired
    private ShipInfoService shipInfoService;

    @RequestMapping("add")
    @SaCheckPermission(PermissionConstant.System_ShipMng_Add)
    public SaResult add(@RequestBody @Validated ShipInfo shipInfo){
        if (!shipInfoService.save(shipInfo)) {
            return SaResult.error();
        }
        return SaResult.ok();
    }

    @RequestMapping("del")
    @SaCheckPermission(PermissionConstant.System_ShipMng_Del)
    public SaResult del(@RequestBody ShipInfo shipInfo){
        if (!shipInfoService.logicDelete(shipInfo)) {
            return SaResult.error();
        }
        return SaResult.ok();
    }


    @RequestMapping("mod")
    @SaCheckPermission(PermissionConstant.System_ShipMng_Mod)
    public SaResult mod(@RequestBody ShipInfo shipInfo){
        if (!shipInfoService.updateById(shipInfo)) {
            return SaResult.error();
        }
        return SaResult.ok();
    }


    @RequestMapping("list")
    @SaCheckPermission(PermissionConstant.System_ShipMng_Qry)
    public SaResult list(@RequestBody PageQueryVo pageQueryVo){
        return SaResult.ok().setData(shipInfoService.selectPage(pageQueryVo));
    }
}